<template>
  <div class="outside">
    <!--<viewhand :deleteids="this.needid"></viewhand>-->
    <el-row :gutter="20" class="seachnav">
      <el-col :xs="7" :sm="6" :md="4" :lg="6" :xl="3">
        <span><img :src="returnnormalpress" class="returnnormalpress"/></span>
        <span><img :src="titles" class="equiplist"/><div style="margin-top: 2px;float: right;"><span style="font-size: 18px; margin-left: 10px;">报表</span></div></span>
      </el-col>
    </el-row>
    <div class="topContent">
      <span class="topSpen" style="font-weight: bold">报表</span>
      <el-dropdown @command="handleCommand" trigger="click">
        <span class="el-dropdown-link topSpen">
          {{this.news}}<i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="全部">全部</el-dropdown-item>
          <el-dropdown-item command="日报">日报</el-dropdown-item>
          <el-dropdown-item command="周报">周报</el-dropdown-item>
          <el-dropdown-item command="月报">月报</el-dropdown-item>
          <el-dropdown-item command="年报">年报</el-dropdown-item>
          <el-dropdown-item command="综合报表">综合报表</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <span style="color: #666666; font-size: 14px">生成时间:</span>
      <el-date-picker
        v-model="startTime"
        @change="startTimeCange"
        type="datetime"
        class="topInput"
        format="yyyy-MM-dd HH:mm:ss"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="开始日期">
      </el-date-picker>
      <span style="font-size: 14px;">到</span>
      <el-date-picker
        v-model="endTime"
        @change="endTimeCange"
        type="datetime"
        class="topInput"
        format="yyyy-MM-dd HH:mm:ss"
        value-format="yyyy-MM-dd HH:mm:ss"
        placeholder="结束日期">
      </el-date-picker>
    </div>
    <div class="organizationOutMore">
      <el-dialog
        title="新增报表"
        :visible.sync="dialogReports"
        width="540px"
        class="reportDialog"
        style="margin-top: 20vh;">
        <el-form class="safelook" :model="addReport" label-width="75px">
          <el-form-item class label="报表名称:">
            <el-input class="addInput" v-model="addReport.data.build_data.name" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="类型:">
            <el-select class="addSelect" @change="typeSelect" v-model="addReportType" filterable placeholder="请选择类型">
              <el-option
                v-for="item in reportsType"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="报表模板:">
            <el-input v-if="!this.addReportType" class="addInput" placeholder="请先选择报表类型" readonly></el-input>
            <el-select v-if="this.addReportType" class="addSelect" v-model="addTemplateType" filterable placeholder="请选择模板">
              <el-option
                v-for="item in templateType"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <!--<el-form-item label="适用对象:">-->
            <!--<el-select class="addSelectHalf" v-model="addReport.data.build_data.first_level" filterable placeholder="一级分类">-->
              <!--<el-option-->
                <!--v-for="item in reportsObjectFst"-->
                <!--:key="item.value"-->
                <!--:label="item.label"-->
                <!--:value="item.value">-->
              <!--</el-option>-->
            <!--</el-select>-->
            <!--<el-select class="addSelectHalf" v-model="addReport.data.build_data.second_level" filterable placeholder="二级分类">-->
              <!--<el-option-->
                <!--v-for="item in reportObjectSnd"-->
                <!--:key="item.value"-->
                <!--:label="item.label"-->
                <!--:value="item.value">-->
              <!--</el-option>-->
            <!--</el-select>-->
          <!--</el-form-item>-->
          <el-form-item label="生成时间:">
            <el-input v-if="!this.addReportType" class="addInput" placeholder="请先选择报表类型" readonly></el-input>
            <!--日报-->
            <el-time-picker
              v-if="this.addReportType === 1 || this.addReportType === 5"
              v-model="addReport.data.build_data.build_time"
              class="addInput"
              format="HH:mm"
              value-format="HH:mm"
              placeholder="任意时间点">
            </el-time-picker>
            <!--周报-->
            <el-select v-if="this.addReportType === 2" class="addWeekSelect" v-model="addWeekType" filterable placeholder="请选择">
              <el-option
                v-for="item in weekType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-time-picker
              v-if="this.addReportType === 2"
              v-model="addReport.data.build_data.build_time"
              class="addInput"
              style="width: 310px"
              format="HH:mm"
              value-format="HH:mm"
              placeholder="任意时间点">
            </el-time-picker>
            <!--月报-->
            <el-select v-if="this.addReportType === 3" class="addWeekSelect" v-model="addMonthType" filterable placeholder="选择日期">
              <el-option
                v-for="item in monthType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-time-picker
              v-if="this.addReportType === 3"
              v-model="addReport.data.build_data.build_time"
              class="addInput"
              style="width: 310px"
              format="HH:mm"
              value-format="HH:mm"
              placeholder="任意时间点">
            </el-time-picker>
            <!--年报-->
            <el-select v-if="this.addReportType === 4" class="addWeekSelect" @change="yearChange" v-model="addYearType" filterable placeholder="选择月份">
              <el-option
                v-for="item in yearType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-select v-if="this.addReportType === 4" class="addWeekSelect" v-model="addMonthType" filterable placeholder="选择日期">
              <el-option
                v-for="item in monthType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-time-picker
              v-if="this.addReportType === 4"
              v-model="addReport.data.build_data.build_time"
              class="addInput"
              style="width: 195px"
              format="HH:mm"
              value-format="HH:mm"
              placeholder="任意时间点">
            </el-time-picker>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button class="clears" @click="dialogReports = false">取 消</el-button>
          <el-button type="primary" style="float: right" @click="addReportWork">保 存</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="编辑报表"
        :visible.sync="dialogEditReports"
        width="540px"
        class="reportDialog"
        style="margin-top: 20vh;">
        <el-form class="safelook" :model="editData" label-width="75px">
          <el-form-item class label="报表名称:">
            <el-input class="addInput" v-model="editData.name" placeholder="请输入"></el-input>
          </el-form-item>
          <el-form-item label="类型:">
            <el-select class="addSelect" @change="typeSelect" v-model="editReportType" filterable placeholder="请选择类型">
              <el-option
                v-for="item in reportsType"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="报表模板:">
            <el-select class="addSelect" v-model="editTemplateType" filterable placeholder="请选择模板">
              <el-option
                v-for="item in templateType"
                :key="item.id"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <!--<el-form-item label="适用对象:">-->
            <!--<el-select class="addSelectHalf" v-model="editData.first_level" filterable placeholder="一级分类">-->
              <!--<el-option-->
                <!--v-for="item in reportsObjectFst"-->
                <!--:key="item.value"-->
                <!--:label="item.label"-->
                <!--:value="item.value">-->
              <!--</el-option>-->
            <!--</el-select>-->
            <!--<el-select class="addSelectHalf" v-model="editData.second_level" filterable placeholder="二级分类">-->
              <!--<el-option-->
                <!--v-for="item in reportObjectSnd"-->
                <!--:key="item.value"-->
                <!--:label="item.label"-->
                <!--:value="item.value">-->
              <!--</el-option>-->
            <!--</el-select>-->
          <!--</el-form-item>-->
          <el-form-item label="生成时间:">
            <!--日报-->
            <el-time-picker
              v-if="this.editReportType === 1 || this.editReportType === 5"
              v-model="editData.build_time"
              class="addInput"
              format="HH:mm"
              value-format="HH:mm"
              placeholder="任意时间点">
            </el-time-picker>
            <!--周报-->
            <el-select v-if="this.editReportType === 2" class="addWeekSelect" v-model="editData.build_date" filterable placeholder="请选择">
              <el-option
                v-for="item in weekType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-time-picker
              v-if="this.editReportType === 2"
              v-model="editData.build_time"
              class="addInput"
              style="width: 310px"
              format="HH:mm"
              value-format="HH:mm"
              placeholder="任意时间点">
            </el-time-picker>
            <!--月报-->
            <el-select v-if="this.editReportType === 3" class="addWeekSelect" v-model="editData.build_date" filterable placeholder="选择日期">
              <el-option
                v-for="item in monthType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-time-picker
              v-if="this.editReportType === 3"
              v-model="editData.build_time"
              class="addInput"
              style="width: 310px"
              format="HH:mm"
              value-format="HH:mm"
              placeholder="任意时间点">
            </el-time-picker>
            <!--年报-->
            <el-select v-if="this.editReportType === 4" class="addWeekSelect" @change="yearChange" v-model="editData.build_date" filterable placeholder="选择月份">
              <el-option
                v-for="item in yearType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-select v-if="this.editReportType === 4" class="addWeekSelect" v-model="editData.build_date" filterable placeholder="选择日期">
              <el-option
                v-for="item in monthType"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
            <el-time-picker
              v-if="this.editReportType === 4"
              v-model="editData.build_time"
              class="addInput"
              style="width: 195px"
              format="HH:mm"
              value-format="HH:mm"
              placeholder="任意时间点">
            </el-time-picker>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button class="clears" @click="dialogEditReports = false">取 消</el-button>
          <el-button type="primary" style="float: right" @click="editReportWork">保 存</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="查看报表"
        :visible.sync="dialogReportsLook"
        width="540px"
        class="reportDialog"
        style="margin-top: 20vh;">
        <el-form class="safelook" :model="lookData" label-width="75px">
          <el-form-item class label="报表名称:">
            <el-input class="addInput readonly" v-model="lookData.name" placeholder="请输入" readonly></el-input>
          </el-form-item>
          <el-form-item label="类型:">
            <el-input class="addInput readonly" v-model="lookData.type" placeholder="请输入" readonly></el-input>
          </el-form-item>
          <el-form-item label="报表模板:">
            <el-input class="addInput readonly" v-model="lookData.template_name" placeholder="请输入" readonly></el-input>
          </el-form-item>
          <!--<el-form-item label="适用对象:">-->
            <!--<el-input class="addInput readonly" v-model="lookData.suitable_object" placeholder="请输入" readonly></el-input>-->
          <!--</el-form-item>-->
          <el-form-item label="生成时间:">
            <!--日报-->
            <el-input v-if="lookData.type_id === 1 || lookData.type_id === 5" class="addInput readonly" v-model="lookData.build_time" placeholder="请输入" readonly></el-input>
            <!--周报/月报/年报-->
            <el-input v-if="lookData.type_id === 2 || lookData.type_id === 3 || lookData.type_id === 4" class="addWeekSelect readonly" v-model="lookData.build_date" placeholder="请输入" readonly></el-input>
            <el-input v-if="lookData.type_id === 2 || lookData.type_id === 3 || lookData.type_id === 4" class="addInput readonly" style="width: 310px" v-model="lookData.build_time" placeholder="请输入" readonly></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button class="clears" @click="dialogReportsLook = false">返 回</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="提示"
        :visible.sync="dialogDisable"
        width="540px"
        class="reportDialog reportEnableDialog"
        style="margin-top: 20vh;">
        <div style="width: 100%; text-align: center; height: 100px; padding-top: 35px;">
          <img :src="disableIcon"/>
        </div>
        <span>确认禁用此报表</span>
        <span slot="footer" class="dialog-footer">
          <el-button class="clears" @click="dialogDisable = false">取 消</el-button>
          <el-button type="primary" style="float: right" @click="enableWork">确 定</el-button>
        </span>
      </el-dialog>
      <el-dialog
        title="提示"
        :visible.sync="dialogEnable"
        width="540px"
        class="reportDialog reportEnableDialog"
        style="margin-top: 20vh;">
        <div style="width: 100%; text-align: center; height: 100px; padding-top: 35px;">
          <img :src="enableIcon"/>
        </div>
        <span>确认启用此报表</span>
        <span slot="footer" class="dialog-footer">
          <el-button class="clears" @click="dialogEnable = false">取 消</el-button>
          <el-button type="primary" style="float: right" @click="enableWork">确 定</el-button>
        </span>
      </el-dialog>
      <el-form :inline="true" class="demo-form-inline">
        <el-form-item class="handItem">
          <el-button type="primary" @click="addReports">新增</el-button>
        </el-form-item>
        <el-form-item class="handItem topRight">
          <div class="pagination-container footerPage">
            <el-pagination
              @current-change="CurrentChange"
              @size-change="SizeChange"
              :page-sizes="[5, 10, 20, 50]"
              background layout="total, sizes, prev, pager, next"
              :total="total">
            </el-pagination>
          </div>
        </el-form-item>
      </el-form>
    </div>
    <div class="organizationTable">
      <el-table :key='tableKey' :data="reportsData" stripe fit highlight-current-row height="814" ref="thetree"
                style="width: 100%;" :header-cell-style="{background:'#F7F8F9',height: '20px',padding:'10px 0px'}">
        <el-table-column
          prop="index"
          label="序号"
          align="center"
          width="60">
        </el-table-column>
        <el-table-column
          prop="name"
          label="报表名称"
          width="280"
          align="left">
        </el-table-column>
        <el-table-column
          prop="type"
          label="类型"
          sortable
          width="220"
          align="left">
        </el-table-column>
        <el-table-column
          prop="build_time"
          label="生成时间"
          sortable
          width="220"
          align="left">
        </el-table-column>
        <el-table-column
          prop="template_name"
          label="模板名称"
          width="220"
          align="left">
        </el-table-column>
        <el-table-column
          prop="suitable_object"
          label="适用对象"
          width="220"
          align="left">
        </el-table-column>
        <el-table-column
          prop="enable"
          label="状态"
          sortable
          width="100">
          <template slot-scope="scope">
            <el-tag
              :type="scope.row.enable === '启用' ? 'primary' : 'success'"
              disable-transitions>{{scope.row.enable}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="创建时间"
          sortable
          min-width="220">
        </el-table-column>
        <el-table-column
          label="操作"
          width="150">
          <template slot-scope="scope">
            <el-button @click="lookDialog(scope.$index,scope.row)" class="tableIcon" type="text" title="查看" size="small">
              <img :src="detail" alt="查看"/>
            </el-button>
            <el-button @click="editDialog(scope.$index,scope.row)" class="tableIcon" type="text" title="编辑" size="small">
              <img :src="redact" alt="编辑"/>
            </el-button>
            <span class="reportsSpan">l</span>
            <el-button v-if="scope.row.enable === '禁用'" @click="enableDialog(scope.$index,scope.row)" class="tableIcon" type="text" title="启用" size="small">
              <img :src="enable" alt="启用"/>
            </el-button>
            <el-button v-if="scope.row.enable === '启用'" @click="disableDialog(scope.$index,scope.row)" class="tableIcon" type="text" title="禁用" size="small">
              <img :src="disabled" alt="禁用"/>
            </el-button>
            <!--<span class="reportsSpan">l</span>-->
            <!--<el-button @click="dialogReports = true" class="tableIcon" type="text" title="替换模板" size="small">-->
              <!--<img :src="replace" alt="替换模板"/>-->
            <!--</el-button>-->
            <ETLdelete></ETLdelete>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
  import ETLdelete from '@/views/configurationETL/component/delete'
  import detail from '@/assets/reports/detail_normal.png'
  import redact from '@/assets/reports/redact_normal.png'
  import enable from '@/assets/reports/enable_normal.png'
  import disabled from '@/assets/reports/disabled_normal.png'
  import replace from '@/assets/reports/replace_normal.png'
  import titles from '@/assets/reports/title.png'
  import disableIcon from '@/assets/mSiteAdmin/disable-icon.png'
  import enableIcon from '@/assets/mSiteAdmin/enable-icon.png'
  import wraningDelete from '@/assets/components/wraningDelete.png'
  import returnnormalpress from '@/assets/reports/invalid.png'
  import equiplist from '@/assets/reports/title.png'
  import searchinvalid from '@/assets/equipv2/searchinvalid.png'
  import axios from 'axios'
  export default {
    components: {
      ETLdelete
    },
    data() {
      return {
        detail,
        redact,
        replace,
        enable,
        disabled,
        wraningDelete,
        disableIcon,
        enableIcon,
        returnnormalpress,
        equiplist,
        searchinvalid,
        titles,
        news: '全部',
        activeName: 'second',
        tableKey: 0,
        dialogReports: false,
        dialogReportsLook: false,
        dialogEditReports: false,
        dialogDisable: false,
        dialogEnable: false,
        reportsType: [],
        reportsObjectFst: [{
          label: '起重机',
          value: '0001'
        }],
        reportsData: [],
        templateType: [],
        reportObjectSnd: [],
        weekType: [{
          label: '星期一',
          value: 'monday'
        }, {
          label: '星期二',
          value: 'tuesday'
        }, {
          label: '星期三',
          value: 'wednesday'
        }, {
          label: '星期四',
          value: 'thursday'
        }, {
          label: '星期五',
          value: 'friday'
        }, {
          label: '星期六',
          value: 'saturday'
        }, {
          label: '星期日',
          value: 'sunday'
        }],
        monthType: [],
        yearType: [{
          label: '1月',
          value: '01'
        }, {
          label: '2月',
          value: '02'
        }, {
          label: '3月',
          value: '03'
        }, {
          label: '4月',
          value: '04'
        }, {
          label: '5月',
          value: '05'
        }, {
          label: '6月',
          value: '06'
        }, {
          label: '7月',
          value: '07'
        }, {
          label: '8月',
          value: '08'
        }, {
          label: '9月',
          value: '09'
        }, {
          label: '10月',
          value: '10'
        }, {
          label: '11月',
          value: '11'
        }, {
          label: '12月',
          value: '12'
        }],
        // 新增报表
        addReportType: '',
        addTemplateType: '',
        addWeekType: '',
        addMonthType: '',
        addYearType: '',
        lookData: {
          build_date: '',
          build_time: '',
          create_time: '',
          enable: '',
          first_level: '',
          id: '',
          name: '',
          second_level: '',
          suitable_object: '',
          template_id: '',
          template_name: '',
          type: '',
          type_id: ''
        },
        editReportType: '',
        editTemplateType: '',
        editData: {
          build_date: '',
          build_time: '',
          create_time: '',
          enable: '',
          first_level: '',
          id: '',
          name: '',
          second_level: '',
          suitable_object: '',
          template_id: '',
          template_name: '',
          type: '',
          type_id: ''
        },
        startTime: '',
        endTime: '',
        siteListQuery: {
          page: 1,
          limit: 20,
          importance: undefined,
          title: undefined,
          type: undefined,
          sort: '+id'
        },
        siteList: [],
        total: 1,
        // localStorage.getItem('access_token')
        // 报表总览
        submitReports: {
          access_token: localStorage.getItem('access_token'),
          type: 'build_overview',
          data: {
            begin_time: '',
            end_time: '',
            type: ''
          },
          page: {
            page_size: '10',
            page_num: '1'
          }
        },
        // 新增报表
        addReport: {
          access_token: localStorage.getItem('access_token'),
          type: 'build_add',
          data: {
            build_data: {
              name: '',
              type_id: '',
              build_time: '',
              build_date: '',
              first_level: '',
              second_level: '',
              template_id: '',
              enable: true
            }
          }
        },
        // 编辑报表
        editReport: {
          access_token: localStorage.getItem('access_token'),
          type: 'build_mod',
          data: {
            build_data: {
              id: '',
              name: '',
              type_id: 1,
              build_time: '',
              build_date: '',
              first_level: '',
              second_level: '',
              template_id: 1
            }
          }
        },
        // 查看报表
        lookReport: {
          access_token: localStorage.getItem('access_token'),
          type: 'build_query',
          data: {
            id: '1'
          }
        },
        // 模板启用状态
        reportEnable: {
          access_token: localStorage.getItem('access_token'),
          type: 'build_enable',
          data: {
            build_data: {
              id: 0,
              enable: false
            }
          }
        },
        // 获取报表模板
        submitTemplate: {
          access_token: localStorage.getItem('access_token'),
          type: 'template_overview_type',
          data: {
            template_data: {
              type_id: 1
            }
          }
        },
        // 获取报表类型
        submitReportType: {
          access_token: localStorage.getItem('access_token'),
          type: 'report_type_get'
        },
        // 获取适用对象二级类型
        submitObjectSnd: {
          access_token: localStorage.getItem('access_token'),
          type: 'equip_get_crane_type'
        }
      }
    },
    created() {
      this.getAllReports()
    },
    methods: {
      getAllReports() {
        this.reportsData = []
        axios.post('/report', this.submitReports, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.reportsData = res.data.data.items
          this.total = parseInt(res.data.data.page.total)
          for (let a = 0; a < this.reportsData.length; a++) {
            this.reportsData[a].index = (a + 1) + (res.data.data.page.page_num - 1) * res.data.data.page.page_size
            if (this.reportsData[a].enable === true) {
              this.reportsData[a].enable = '启用'
            } else {
              this.reportsData[a].enable = '禁用'
            }
          }
        })
          .catch((error) => {
            console.log(error)
          })
      },
      CurrentChange(val) {
        this.submitReports.page.page_num = (val) + ''
        this.getAllReports()
      },
      SizeChange(pageSize) {
        this.submitReports.page.page_size = (pageSize) + ''
        this.getAllReports()
      },
      typeSelect() {
        this.editData.build_date = ''
        if (this.addReportType === 4 || this.editReportType === 4) {
          this.monthType.push({ lable: '先选月份', value: '先选月份' })
          this.addMonthType = '先选月份'
          this.editData.build_date = '先选月份'
        } else if (this.addReportType === 3 || this.editReportType === 3) {
          this.monthType = []
          this.addMonthType = ''
          this.editData.build_date = ''
          for (let a = 1; a < 32; a++) {
            var day = a
            if (day.toString().length === 1) {
              day = '0' + day
            }
            this.monthType.push({ lable: day, value: day })
          }
        }
        this.addTemplateType = ''
        this.editTemplateType = ''
        if (this.dialogEditReports === true) {
          this.submitTemplate.data.template_data.type_id = this.editReportType
        } else {
          this.submitTemplate.data.template_data.type_id = this.addReportType
        }
        this.getTemplate()
      },
      yearChange() {
        if (this.addYearType === '02') {
          this.addMonthType = ''
          this.monthType = []
          for (let b = 1; b < 29; b++) {
            var dayone = b
            if (dayone.toString().length === 1) {
              dayone = '0' + dayone
            }
            this.monthType.push({ lable: dayone, value: dayone })
          }
        } else {
          this.addMonthType = ''
          this.monthType = []
          for (let c = 1; c < 32; c++) {
            var day = c
            if (day.toString().length === 1) {
              day = '0' + day
            }
            this.monthType.push({ lable: day, value: day })
          }
        }
      },
      startTimeCange() {
        if (this.startTime) {
          this.submitReports.data.begin_time = this.startTime
          this.getAllReports()
        } else {
          this.submitReports.data.begin_time = ''
          this.getAllReports()
        }
      },
      endTimeCange() {
        if (this.endTime) {
          this.submitReports.data.end_time = this.endTime
          this.getAllReports()
        } else {
          this.submitReports.data.end_time = ''
          this.getAllReports()
        }
      },
      handleCommand(command) {
        this.news = command
        if (this.news === '全部') {
          this.submitReports.data.type = ''
          this.submitReports.page.page_num = '1'
          this.getAllReports()
        } else if (this.news === '日报') {
          this.submitReports.data.type = '1'
          this.submitReports.page.page_num = '1'
          this.getAllReports()
        } else if (this.news === '周报') {
          this.submitReports.data.type = 'week'
          this.submitReports.page.page_num = '1'
          this.getAllReports()
        } else if (this.news === '月报') {
          this.submitReports.data.type = 'month'
          this.submitReports.page.page_num = '1'
          this.getAllReports()
        } else if (this.news === '年报') {
          this.submitReports.data.type = 'year'
          this.submitReports.page.page_num = '1'
          this.getAllReports()
        } else if (this.news === '综合报表') {
          this.submitReports.data.type = 'other'
          this.submitReports.page.page_num = '1'
          this.getAllReports()
        }
      },
      addReports() {
        this.addReport.data.build_data.name = ''
        this.addReportType = ''
        this.addTemplateType = ''
        this.addReport.data.build_data.build_time = ''
        this.addReport.data.build_data.first_level = ''
        this.addReport.data.build_data.second_level = ''
        this.addWeekType = ''
        this.addMonthType = ''
        this.addYearType = ''
        this.templateType = []
        axios.post('/report', this.submitReportType, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.reportsType = res.data.datas
        })
          .catch((error) => {
            console.log(error)
          })
        axios.post('/basicdata', this.submitObjectSnd, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.reportObjectSnd = res.data.datas
        })
          .catch((error) => {
            console.log(error)
          })
        this.dialogReports = true
      },
      getTemplate() {
        axios.post('/template', this.submitTemplate, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.templateType = res.data.datas
        })
          .catch((error) => {
            console.log(error)
          })
      },
      addReportWork() {
        if (this.addReportType) {
          this.addReport.data.build_data.type_id = this.addReportType
        }
        if (this.addTemplateType) {
          this.addReport.data.build_data.template_id = this.addTemplateType
        }
        if (this.addReport.data.build_data.type_id === 2) {
          this.addReport.data.build_data.build_date = this.addWeekType
        } else if (this.addReport.data.build_data.type_id === 3) {
          this.addReport.data.build_data.build_date = this.addMonthType
        } else if (this.addReport.data.build_data.type_id === 4) {
          this.addReport.data.build_data.build_date = this.addYearType + '-' + this.addMonthType
        }
        if (!this.addReport.data.build_data.name) {
          this.$message.error('请输入报表名称')
          return
        }
        if (!this.addReport.data.build_data.type_id) {
          this.$message.error('请选择报表类型')
          return
        }
        if (!this.addReport.data.build_data.template_id) {
          this.$message.error('请选择报表模板')
          return
        }
        if (!this.addReport.data.build_data.first_level || !this.addReport.data.build_data.second_level) {
          this.$message.error('请选择适用对象')
          return
        }
        if (this.addReport.data.build_data.type_id !== 1 && this.addReport.data.build_data.type_id !== 5) {
          if (!this.addReport.data.build_data.build_date) {
            this.$message.error('请选择生成日期')
            return
          }
        }
        if (!this.addReport.data.build_data.build_time) {
          this.$message.error('请选择生成时间')
          return
        }
        axios.post('/report', this.addReport, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.dialogReports = false
          this.getAllReports()
        })
          .catch((error) => {
            this.$message.error(error.data.errmsg)
          })
      },
      lookDialog(index, row) {
        this.lookReport.data.id = String(row.id)
        axios.post('/report', this.lookReport, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.lookData = res.data.data
          this.dialogReportsLook = true
        })
          .catch((error) => {
            console.log(error)
          })
      },
      enableDialog(index, row) {
        this.reportEnable.data.build_data.id = row.id
        this.reportEnable.data.build_data.enable = true
        this.dialogEnable = true
      },
      disableDialog(index, row) {
        this.reportEnable.data.build_data.id = row.id
        this.reportEnable.data.build_data.enable = false
        this.dialogDisable = true
      },
      enableWork() {
        axios.post('/report', this.reportEnable, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.reportEnable.data.build_data.id = 0
          this.dialogEnable = false
          this.dialogDisable = false
          this.getAllReports()
        })
          .catch((error) => {
            this.$message.error(error.data.errmsg)
          })
      },
      editDialog(index, row) {
        this.lookReport.data.id = String(row.id)
        axios.post('/report', this.lookReport, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.editData = res.data.data
          this.editReportType = res.data.data.type_id
          this.editTemplateType = res.data.data.template_id
          this.submitTemplate.data.template_data.type_id = res.data.data.type_id
          this.getTemplate()
          this.dialogEditReports = true
        })
          .catch((error) => {
            console.log(error)
          })
        axios.post('/report', this.submitReportType, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.reportsType = res.data.datas
        })
          .catch((error) => {
            console.log(error)
          })
        axios.post('/basicdata', this.submitObjectSnd, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.reportObjectSnd = res.data.datas
        })
          .catch((error) => {
            console.log(error)
          })
      },
      editReportWork() {
        this.editData.type_id = this.editReportType
        this.editData.template_id = this.editTemplateType
        if (!this.editData.name) {
          this.$message.error('请输入报表名称')
          return
        }
        if (!this.editData.type_id) {
          this.$message.error('请选择报表类型')
          return
        }
        if (!this.editData.template_id) {
          this.$message.error('请选择报表模板')
          return
        }
        if (!this.editData.first_level || !this.editData.second_level) {
          this.$message.error('请选择适用对象')
          return
        }
        if (this.editReportType !== 1 && this.editReportType !== 5) {
          if (!this.editData.build_date) {
            this.$message.error('请选择生成日期')
            return
          }
        }
        if (!this.editData.build_time) {
          this.$message.error('请选择生成时间')
          return
        }
        this.editReport.data.build_data = this.editData
        axios.post('/report', this.editReport, {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then((res) => {
          this.getAllReports()
          this.dialogEditReports = false
        })
          .catch((error) => {
            this.$message.error(error.data.errmsg)
          })
        // this.dialogEditReports = false
      }
    }
  }
</script>

<style scoped>
  /*顶部start*/
  .outside {
    padding: 0px 20px 20px 20px;
    background: #EFEFEF;
  }
  .topContent {
    width: 100%;
    height: 50px;
    padding: 15px 15px 15px 0px;
  }
  .topSpen {
    font-size: 14px;
    margin-right: 20px;
    color: #333333;
  }
  .topInput {
    width: 200px;
    height: 24px;
  }
  /deep/ .topInput > .el-input__inner {
    height: 24px;
  }
  .organizationOutMore{
    width: 100%;
    height: 40px;
    background-color: #ffffff;
    padding-left: 10px;
  }
  .sitetitle {
    float: left;
    color: #323842;
    font-size: 14px;
    font-weight: bold;
    margin-top: 12px;
    margin-right: 40px;
  }
  /deep/ label {
    font-weight: normal;
    color: #69727E;
  }
  /deep/ .handItem {
    margin-bottom: 5px!important;
  }
  /deep/ .topRight {
    float: right;
    height: 30px;
  }
  /deep/ .reset {
    padding: 6px 16px;
    background-color: #333B3D;
    border-color: #333B3D ;
    color: #fff;
  }
  /deep/ .el-button + .el-button {
    margin-left: 5px;
  }
  /deep/ .el-button--primary {
    height: 24px;
    font-size: 14px;
    padding: 3px 16px;
    background: #0072F3;
    border-color: #0072F3;
  }
  /*/deep/ .el-message-box{*/
  /*width: 540px;*/
  /*}*/
  /*/deep/ .el-message-box__header{*/
  /*background-color: #E3E6EE;*/
  /*padding: 10px 15px;*/
  /*}*/
  /*/deep/ .el-message-box__title{*/
  /*font-size: 18px;*/
  /*font-weight: Bold;*/
  /*color: #323842;*/
  /*}*/
  /*/deep/ .el-message-box__status{*/
  /*right: 247px;*/
  /*top: 65px;*/
  /*font-size: 48px !important;*/
  /*}*/
  /*/deep/ .el-message-box__status.el-icon-warning{*/
  /*color: #E53D41;*/
  /*}*/
  /*/deep/ .el-message-box__content{*/
  /*height: 182px;*/
  /*}*/
  /*/deep/ .el-message-box__message p {*/
  /*margin: 0;*/
  /*font-size: 18px;*/
  /*color: #323842;*/
  /*padding-top: 96px;*/
  /*text-indent: 0px;*/
  /*text-align: center;*/
  /*}*/
  /*/deep/ .el-message-box__headerbtn{*/
  /*top: 9px;*/
  /*font-size: 18px;*/
  /*}*/
  /*/deep/ .el-message-box__btns{*/
  /*padding: 10px 15px 7px ;*/
  /*border-top: 1px solid #e8eaf1;*/
  /*}*/
  /*顶部end*/
  /deep/ .organizationTable{
    width: 100%;
    min-height: 500px;
    background-color: #fff;
  }
  /deep/ .tableIcon {
    padding: 0px;
    font-size: 20px;
    font-weight: 500;
  }
  .el-popper[x-placement^="bottom"] {
    margin-top: 12px;
    width: 98px;
    color: #e0e0e0;
  }
  /deep/ .el-input__icon {
    line-height: 24px;
  }
  /deep/ .el-button--text {
    color: #31BACB;
  }
  /deep/ .el-table th {
    padding: 3px;
    background: #F7F8F9!important;
  }
  /deep/ .el-table td {
    padding: 5px 0px;
    border: none;
  }
  /deep/ .el-button + .el-button {
    margin-left: 5px;
  }
  /deep/ .addInput {
    width: 100%;
  }
  /deep/ .addInput > .el-input__inner {
    height: 30px;
  }
  /deep/ .readonly > .el-input__inner {
    border: none;
  }
  /deep/ .addSelect {
    width: 100%;
  }
  /deep/ .addSelect > .el-input > .el-input__inner {
    height: 30px;
  }
  /deep/ .addSelectHalf {
    width: 49.5%;
  }
  /deep/ .addSelectHalf > .el-input > .el-input__inner {
    height: 30px;
  }
  /deep/ .addWeekSelect {
    width: 110px;
  }
  /deep/ .addWeekSelect > .el-input__inner {
    height: 30px;
  }
  /deep/ .addWeekSelect > .el-input > .el-input__inner {
    height: 30px;
  }
  /deep/ .delete {
    display: inline;
    margin-left: 5px;
  }
  /deep/ .clears{
    padding: 6px 16px;
    background-color: #526D89;
    border-color: #526D89;
    color: #fff;
    float: right;
    margin-left: 10px;
  }
  /deep/ .el-dialog {
    border-radius: 5px;
  }
  /deep/ .el-dialog__header {
    background: #E3E6EE;
    font-size: 18px;
    font-weight: bold;
    padding: 12px 20px 9px 20px;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    line-height: 20px;
  }
  /deep/ .el-dialog__headerbtn {
    top: 15px;
  }
  /deep/ .el-dialog__body {
    padding: 20px;
  }
  /deep/ .reportDialog > .el-dialog > .el-dialog__body {
    text-align: center;
    font-size: 18px;
    height: 205px;
    border-bottom: 1px solid #e8eaf1;
  }
  /deep/ .reportEnableDialog > .el-dialog > .el-dialog__body {
    height: 210px;
  }
  /deep/ .reportDialog > .el-dialog > .el-dialog__footer {
    height: 50px;
    padding: 10px;
  }
  /deep/ .reportDialog > .el-dialog > .el-dialog__footer > .dialog-footer > button {
    height: 30px;
    font-size: 14px;
    padding: 6px 16px;
  }
  /deep/ .safelook > .el-form-item {
    margin-bottom: 0px;
  }
  /deep/ .associatedSearch{
    width: 240px;
    float: left;
    height: 30px;
  }
  /deep/ .associatedNew{
    float: right;
    margin-bottom: 10px;
    height: 30px;
  }
  /deep/ .reportsSpan {
    font-size: 20px;
  }
  /deep/ .footerPage{
    float: right;
    margin-top: 5px;
  }
  /deep/ .el-message-box{
    width: 540px;
  }
  /deep/ .el-message-box__header{
    background-color: #E3E6EE;
    padding: 10px 15px;
  }
  /deep/ .el-message-box__title{
    font-size: 18px;
    font-weight: Bold;
    color: #323842;
  }
  /deep/ .el-message-box__status{
    right: 247px;
    top: 65px;
    font-size: 48px !important;
  }
  /deep/ .el-message-box__status.el-icon-warning{
    color: #E53D41;
  }
  /deep/ .el-message-box__content{
    height: 182px;
  }
  /deep/ .el-message-box__message p {
    margin: 0;
    font-size: 18px;
    color: #323842;
    padding-top: 96px;
    text-indent: 0px;
    text-align: center;
  }
  /deep/ .el-message-box__headerbtn{
    top: 9px;
    font-size: 18px;
  }
  /deep/ .el-message-box__btns{
    padding: 10px 15px 7px ;
    border-top: 1px solid #e8eaf1;
  }
  /deep/ .gutter {
    background: #D8DEE8;
  }
  /deep/ .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #409EFF;
    color: #fff;
  }
  /deep/ .el-tag {
    padding: 0px;
    background-color: transparent;
    border: none;
  }
  /deep/ .el-tag--success {
    background-color: transparent;
    color: #E53D41;
  }
  /deep/ .seachnav {
    width: 60%;
    height: 50px;
    position: fixed;
    z-index: 2;
    top: 0;
    bottom: 0;
    line-height: 50px;
  }
  /deep/ .returnnormalpress{
    vertical-align: middle;
  }
  /deep/ .equiplist{
    vertical-align: middle;
    cursor: pointer;
    margin-left: 20px;
  }
</style>
